package com.smarthospital.entity.im;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * create by sym  2021/5/9 10:39.
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description="IM消息体" )  //swagger 文档
//声明es文档对象
@Document(indexName = "immessage", type = "immessage")   //es注解
public class IMMessage {


    @Id
    @ApiModelProperty(value = "id" )  //swagger 文档
//    @Field(name = "id", index = true, type = FieldType.Keyword, store = true)  //es注解
    private Long id;

    @ApiModelProperty(value = "消息状态 0_对方未读 1_对方已读 2_别人发送的消息" )
    @Field(name = "status", index = true, type = FieldType.Keyword, store = true)
    private int status;

    @ApiModelProperty(value = "消息发送者id" )
    @Field(name = "senderId", index = true, type = FieldType.Keyword, store = true)
    private String senderId;

    @ApiModelProperty(value = "消息接收者id" )
    @Field(name = "receiverId", index = true, type = FieldType.Keyword, store = true)
    private String receiverId;

    @ApiModelProperty(value = "订单id 也是房间id" )
    @Field(name = "orderId", index = true, type = FieldType.Keyword, store = true)
    private String orderId;

    @ApiModelProperty(value = "类型 0_文字类型  1_图片 2_音频记录 3_视频记录 4_系统通知文本消息 5_系统通知图片信息(广告推送)" )
    @Field(name = "type", index = true, type = FieldType.Keyword, store = true)
    private int type;

    @ApiModelProperty(value = "文本消息内容" )
    @Field(name = "content", index = true, type = FieldType.Keyword, store = true)
    private String content;

    @ApiModelProperty(value = "音频视屏时长 单位秒" )
    @Field(name = "time", index = true, type = FieldType.Keyword, store = true)
    private int time;

    @ApiModelProperty(value = "消息发送时间" )
    @Field(name = "dateTime", index = true, type = FieldType.Date, store = true,pattern = "yyyy-MM-dd HH:mm:ss",format = DateFormat.custom)
    private String dateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());

    @ApiModelProperty(value = "消息时间戳" )
    @Field(name = "timeStamp", index = true, type = FieldType.Long, store = true)
    private long timeStamp = System.currentTimeMillis();

    public static List<IMMessage> ListIms(String content){
        List<IMMessage> imMessages = new ArrayList<>();
        IMMessage imMessage = new IMMessage();
        imMessage.setContent(content);
        imMessages.add(imMessage);
        return  imMessages;
    }
    //接入时的通知消息
    public static  IMMessage TIP_ON_OPEN;
    static {
        IMMessage imMessage = new IMMessage();
        imMessage.setType(4);
        imMessage.setContent("以上是历史消息");
        TIP_ON_OPEN = imMessage;
    }
}
